package amrparser

import (
	"time"
	"xmediaEmu/pkg/decoder/codec"
)

// amr-wb编码.
type AmrWbCodecData struct {
}

func (d AmrWbCodecData) Type() codec.CodecType {
	return codec.AMR_WB
}

func (self AmrWbCodecData) SampleRate() int {
	return 16000
}

func (self AmrWbCodecData) ChannelLayout() codec.ChannelLayout {
	return codec.CH_MONO
}

func (self AmrWbCodecData) SampleFormat() codec.SampleFormat {
	return codec.FLT
}

func (self AmrWbCodecData) PacketDuration(data []byte) (time.Duration, error) {
	return time.Duration(20) * time.Millisecond, nil
}

type AmrNbCodecData struct {
}

func (d AmrNbCodecData) Type() codec.CodecType {
	return codec.AMR_NB
}

func (self AmrNbCodecData) SampleRate() int {
	return 8000
}

func (self AmrNbCodecData) ChannelLayout() codec.ChannelLayout {
	return codec.CH_MONO
}

func (self AmrNbCodecData) SampleFormat() codec.SampleFormat {
	//return codec.S16
	return codec.FLT
}

func (self AmrNbCodecData) PacketDuration(data []byte) (time.Duration, error) {
	return time.Duration(20) * time.Millisecond, nil
}

// ------------ start of open core by hhl -----------------------------------
type AmrNbOpenCoreCodecData struct {
}

func (nb AmrNbOpenCoreCodecData) Type() codec.CodecType {
	return codec.AMR_NB_OPENCORE
}

func (nb AmrNbOpenCoreCodecData) SampleRate() int {
	return 8000
}

func (nb AmrNbOpenCoreCodecData) ChannelLayout() codec.ChannelLayout {
	return codec.CH_MONO
}

func (nb AmrNbOpenCoreCodecData) SampleFormat() codec.SampleFormat {
	return codec.S16
}

func (nb AmrNbOpenCoreCodecData) PacketDuration(data []byte) (time.Duration, error) {
	return time.Duration(20) * time.Millisecond, nil
}

type AmrWbOpenCoreCodecData struct {
}

func (s AmrWbOpenCoreCodecData) Type() codec.CodecType {
	return codec.AMR_WB_OPENCORE
}

func (s AmrWbOpenCoreCodecData) SampleRate() int {
	return 16000
}

func (s AmrWbOpenCoreCodecData) ChannelLayout() codec.ChannelLayout {
	return codec.CH_MONO
}

func (s AmrWbOpenCoreCodecData) SampleFormat() codec.SampleFormat {
	return codec.S16
}

func (s AmrWbOpenCoreCodecData) PacketDuration(data []byte) (time.Duration, error) {
	return time.Duration(20) * time.Millisecond, nil
}

func NewAmrNbOpenCoreCodecData() codec.AudioCodecData {
	return AmrNbOpenCoreCodecData{}
}

func NewAmrWbOpenCoreCodecData() codec.AudioCodecData {
	return AmrWbOpenCoreCodecData{}
}
